package com.wushi.lenovo.asia5b.app_ui.good.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.RadioButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_model.good.DeliveriesBean;
import com.wushi.lenovo.asia5b.app_model.good.bean.OrderMethodInter;
import com.wushi.lenovo.asia5b.app_ui.h5.CategoryActivity;

import java.util.List;

/**
 * Created by zhangyuncai on 2019/2/16.
 */
public class OrderPaymentMethodAdapter<V extends OrderMethodInter> extends BaseQuickAdapter<V, BaseViewHolder> {
    private int selectPosition = 0;

    public OrderPaymentMethodAdapter(@Nullable List<V> data) {
        super(R.layout.item_orderpayment_methodadapter, data);
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
        notifyDataSetChanged();
    }

    public int getSelectPosition() {
        return selectPosition;
    }

    @Override
    protected void convert(BaseViewHolder helper, V item) {
        int position = helper.getLayoutPosition();
        RadioButton radioButton = helper.getView(R.id.rb_method_checked);
        radioButton.setChecked(position == selectPosition);
        radioButton.setText(item.getMethodName());

        if (item instanceof DeliveriesBean) {
            DeliveriesBean bean = (DeliveriesBean) item;
            helper.setGone(R.id.iv_method_info, !TextUtils.isEmpty(bean.getTooltip_url()));
            helper.getView(R.id.iv_method_info).setOnClickListener(v -> {
                CategoryActivity.startCategoryActivity(mContext, bean.getTooltip_url(), "");
            });
        }
    }
}
